import json

from flask import Flask, request
from markupsafe import escape

app = Flask(__name__)


# $ export FLASK_APP=app.py
# $ export FLASK_ENV=development
# $ flask run

@app.route('/')
def hello():
    name = request.args.get("name", "World")
    return f'Hello, {escape(name)}!'


# 接受url拼的参数，返回json数据
@app.route("/json", methods=['GET', 'POST'])
def me_api():
    param = request.args.get('param', '')
    user = {"username": "suzt", "age": "18", "param": param}
    return user


# 接受json数据，返回json数据
@app.route("/jsonPost", methods=['GET', 'POST'])
def json_post():
    param = request.get_data()
    print(param)
    print(type(param))
    json_res = json.loads(param)
    json_res["res"] = "success"
    return json_res
